import axios from 'axios'

import { MessageBox  } from 'element-ui';
import router from '../router'

//请求拦截器
axios.interceptors.request.use(config =>{
    //给请求头添加token
    config.headers.Authorization = localStorage.token
    return config 
}),err => Promise.reject(err)





//响应拦截器
axios.interceptors.response.use((res)=>res.data, (err)=>{
   console.log(err);
   if(err&&err.response&&err.response.status){
       if(err.response.status == 401){

        MessageBox.alert('登陆已过期，请重新登录','警告',{
            confirmButtonText:'确定',
            callback:action =>{
                router.push('/login')
            }
        }
          );
       }
       
   }
    return Promise.reject(err)
})